home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / APPLICAT.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  14KB  |  526 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.11  $
  6. //
  7. // Definition of class TApplication. This defines the basic behavior for OWL
  8. // applications. Also definitions for TBwccDll, TCtl3dDll, TXInvalidMainWindow
  9. //----------------------------------------------------------------------------
  10. #if !defined(OWL_APPLICAT_H)
  11. #define OWL_APPLICAT_H
  12.  
  13. #if !defined(OWL_MODULE_H)
  14. # include <owl/module.h>
  15. #endif
  16. #if !defined(OWL_EVENTHAN_H)
  17. # include <owl/eventhan.h>
  18. #endif
  19. #if !defined(WINSYS_MSGTHRED_H)
  20. # include <winsys/msgthred.h>
  21. #endif
  22.  
  23. #if defined(BI_NAMESPACE)
  24. namespace OWL {
  25. #endif
  26.  
  27. // Generic definitions/compiler options (eg. alignment) preceeding the
  28. // definition of classes
  29. #include <services/preclass.h>
  30.  
  31. //
  32. // Language defines for TApplication::EnableBWCC()
  33. //
  34. #define BWCC_LANG_GERMAN 0x07
  35. #define BWCC_LANG_US     0x09
  36. #define BWCC_LANG_FRENCH 0x0c
  37.  
  38. class _OWLCLASS TWindow;
  39. class _OWLCLASS TFrameWindow;
  40. class _OWLCLASS TDocManager;
  41. class _OWLCLASS TAppDictionary;
  42. class _OWLCLASS_RTL TXInvalidMainWindow;
  43. class _OWLCLASS TBwccDll;
  44. class _OWLCLASS TCtl3dDll;
  45.  
  46. //
  47. // struct TCurrentEvent
  48. // ~~~~~~ ~~~~~~~~~~~~~
  49. // Current event structure for windows events
  50. //
  51. struct TCurrentEvent {
  52.   TWindow*  Win;      // Window that message was sent/dispatched to
  53.   uint      Message;  // Message ID
  54.   union {
  55. #if defined(OWL2_COMPAT)
  56.     TParam1 WParam;   // Old name
  57. #endif
  58.     TParam1 Param1;   // New name of first parameter
  59.   };
  60.   union {
  61. #if defined(OWL2_COMPAT)
  62.     TParam2 LParam;   // Old name
  63. #endif
  64.     TParam2 Param2;   // New name of secont parameter
  65.   };
  66. };
  67.  
  68. //
  69. // class TApplication
  70. // ~~~~~ ~~~~~~~~~~~~
  71. class _OWLCLASS TApplication : virtual public TEventHandler,
  72.                                        public TModule,
  73.                                        public TMsgThread
  74. {
  75.   public:
  76.     // Constructors for TApplication. Default args for the ctor allow
  77.     // TApplication to access global pointers in the user exe/dll.
  78.     // Default OwlAppDictionary can be overridden by passing non-0 appDict arg
  79.     //
  80.     TApplication(const char far* name = 0, TModule*& gModule = ::Module,
  81.                  TAppDictionary* appDict = 0);
  82.     TApplication(const char far* name,
  83.                  HINSTANCE       hInstance,
  84.                  HINSTANCE       hPrevInstance,
  85.                  const char far* cmdLine,
  86.                  int             cmdShow,
  87.                  TModule*&       gModule = ::Module,
  88.                  TAppDictionary* appDict = 0);
  89.  
  90.    ~TApplication();
  91.  
  92.     TFrameWindow*    GetMainWindow();
  93.     TDocManager*     GetDocManager();
  94.  
  95.     static void      SetWinMainParams(HINSTANCE       hInstance,
  96.                                       HINSTANCE       hPrevInstance,
  97.                                       const char far* cmdLine,
  98.                                       int             cmdShow);
  99.  
  100.     void             GetWinMainParams();
  101.  
  102.     HINSTANCE        GetPrevInstance() const;
  103.     void             SetPrevInstance(HINSTANCE pi);
  104.  
  105.     int              GetCmdShow() const;
  106.     void             SetCmdShow(int cmdshow);
  107.  
  108.     static string&   GetCmdLine();
  109.     TCurrentEvent&   GetCurrentEvent();
  110.  
  111.     virtual bool     CanClose();
  112.     virtual int      Run();
  113.     virtual int      Start();
  114.  
  115.     // Message queue thread synchronization mechanism
  116.     //
  117. #if defined(BI_MULTI_THREAD_RTL)
  118.     typedef TMsgThread::TQueueLock TAppLock;
  119.  
  120.     // Override TEventHandler::Dispatch() to handle multi-thread
  121.     // synchronization
  122.     //
  123.     virtual TResult  Dispatch(TEventInfo& info, TParam1 wp, TParam2 lp = 0);
  124. #endif
  125.  
  126.     // Message queue loop & response functions
  127.     //
  128.     virtual int      MessageLoop();
  129.     virtual bool     IdleAction(long idleCount);
  130.     virtual bool     ProcessMsg(MSG& msg);
  131.     virtual bool     ProcessAppMsg(MSG& msg);
  132.  
  133. #if defined(BI_PLAT_WIN16) || defined(WIN32S_SUPPORT)
  134.     // Win16 / Win32s Exception propagation mechanism
  135.     //
  136.     void             SuspendThrow(xalloc& x);
  137.     void             SuspendThrow(xmsg& x);
  138.     void             SuspendThrow(TXBase& x);
  139.     void             SuspendThrow(int);
  140.     void             ResumeThrow();
  141.     int              QueryThrow() const;
  142.     enum {
  143.       xsUnknown   = 1,
  144.       xsBadCast   = 2,
  145.       xsBadTypeid = 4,
  146.       xsMsg       = 8,
  147.       xsAlloc     = 16,
  148.       xsBase      = 32,
  149. #if defined(OWL2_COMPAT)
  150.       xsOwl       = 32,  // For compatibility with Owl 2.0
  151. #endif
  152.     };
  153. #endif
  154.  
  155.     // Get the TWindow pointer belonging to this app given an hWnd
  156.     //
  157.     TWindow*         GetWindowPtr(HWND hWnd) const;
  158.  
  159.     // Begin and end of a modal window's modal message loop
  160.     //
  161.     int              BeginModal(TWindow* window, int flags=MB_APPLMODAL);
  162.     void             EndModal(int result);
  163.     virtual void     PreProcessMenu(HMENU hMenubar);
  164.  
  165.     // Dead TWindow garbage collection
  166.     //
  167.     void             Condemn(TWindow* win);
  168.     void             Uncondemn(TWindow* win);
  169.  
  170.     // Call this function after each msg dispatch if TApplication's message
  171.     // loop is not used.
  172.     //
  173.     void             PostDispatchAction();
  174.  
  175.     // TApplication defers event handling to DocManager if one has been
  176.     // installed.
  177.     //
  178.     bool             Find(TEventInfo&, TEqualOperator = 0);
  179.  
  180.     // Control of UI enhancing libraries
  181.     //
  182.     void             EnableBWCC(bool enable = true, uint language = 0);
  183.     bool             BWCCEnabled() const;
  184.     TBwccDll*        GetBWCCModule() const;
  185.  
  186.     void             EnableCtl3d(bool enable = true);
  187.     void             EnableCtl3dAutosubclass(bool enable);
  188.     bool             Ctl3dEnabled() const;
  189.     TCtl3dDll*       GetCtl3dModule() const;
  190.  
  191.     // Open a modal message box, with appropriate BWCC or Ctl3d handling
  192.     //
  193.     int              MessageBox(HWND hParentWnd,
  194.                                 const char far* text,
  195.                                 const char far* caption = 0,
  196.                                 uint            type = MB_OK);
  197.  
  198. #if defined(OWL2_COMPAT)
  199.     typedef ::TXInvalidMainWindow TXInvalidMainWindow;  // Exceptions moved to global scope
  200. #endif
  201.  
  202.   protected:
  203.     virtual void     InitApplication();
  204.     virtual void     InitInstance();
  205.     virtual void     InitMainWindow();
  206.     virtual int      TermInstance(int status);
  207.  
  208.     // (Re)set a new main-window and DocManager either at construction or
  209.     // sometime later
  210.     //
  211.     TFrameWindow*    SetMainWindow(TFrameWindow* window);
  212.     TDocManager*     SetDocManager(TDocManager* docManager);
  213.  
  214.     // Member data -- use accessors to get at these
  215.     //
  216.   public_data:
  217.     HINSTANCE     hPrevInstance;
  218.     int           nCmdShow;
  219.     TDocManager*  DocManager;
  220.     TFrameWindow* MainWindow;
  221.  
  222. #if defined(OWL2_COMPAT)
  223.     HACCEL        HAccTable;    // Obsolete, use each TWindow's
  224. #endif
  225.  
  226.   protected_data:
  227.     string        CmdLine;                 // string object copy of cmd line
  228.  
  229.   private:
  230.     bool          BWCCOn;
  231.     TBwccDll*     BWCCModule;
  232.  
  233.     bool          Ctl3dOn;
  234.     TCtl3dDll*    Ctl3dModule;
  235.  
  236.     TCurrentEvent CurrentEvent;
  237.  
  238. #if defined(BI_PLAT_WIN16) || defined(WIN32S_SUPPORT)
  239.     // Exception handling state
  240.     //
  241.     int           XState;
  242.     string        XString;
  243.     size_t        XSize;
  244.     TXBase*       XBase;
  245. #endif
  246.  
  247.     // Condemned TWindow garbage collection
  248.     //
  249.     void             DeleteCondemned();
  250.     TWindow*         CondemnedWindows;
  251.  
  252.     // The dictionary that this app is in
  253.     //
  254.     TAppDictionary*  Dictionary;
  255.  
  256.     // Static application initialization parameters cached here before app
  257.     // is actually constructed
  258.     //
  259.     static HINSTANCE  InitHInstance;          // WinMain's 1st param
  260.     static HINSTANCE  InitHPrevInstance;      // WinMain's 2nd param
  261.     static string&    GetInitCmdLine();       // WinMain's 3rd param
  262.     static int        InitCmdShow;            // WinMain's 4th param
  263.  
  264.     // Response tables
  265.     //
  266.     typedef TResponseTableEntry<TApplication>::PMF TMyPMF;
  267.     typedef TApplication                           TMyClass;
  268.  
  269.     static TResponseTableEntry<TApplication> __RTFAR __entries[];
  270.     void CmExit();  // Exit from file menu
  271.  
  272.  
  273.     // Hidden to prevent accidental copying or assignment
  274.     //
  275.     TApplication(const TApplication&);
  276.     TApplication& operator =(const TApplication&);
  277.  
  278.   DECLARE_STREAMABLE(_OWLCLASS, TApplication, 1);
  279. };
  280.  
  281. //
  282. // class TBwccDll
  283. // ~~~~~ ~~~~~~~~
  284. // Wrapper for the BWCC Dll
  285. //
  286. class _OWLCLASS TBwccDll : public TModule {
  287.   public:
  288.     TBwccDll();
  289.  
  290.     // Used by TApplication
  291.     //
  292.     TModuleProc1<bool,uint>      IntlInit;
  293.     TModuleProc1<bool,HINSTANCE> Register;
  294.     TModuleProc0<bool>           IntlTerm;
  295.  
  296.     // Not used by OWL
  297.     //
  298.     TModuleProc3<HGLOBAL,HINSTANCE,LPCSTR,DLGPROC>  SpecialLoadDialog;
  299.     TModuleProc3<HGLOBAL,HGLOBAL,HINSTANCE,DLGPROC> MangleDialog;
  300.     TModuleProc4<LRESULT,HWND,UINT,WPARAM,LPARAM>   DefDlgProc;
  301.     TModuleProc4<LRESULT,HWND,UINT,WPARAM,LPARAM>   DefGrayDlgProc;
  302.     TModuleProc4<LRESULT,HWND,UINT,WPARAM,LPARAM>   DefWindowProc;
  303.     TModuleProc4<LRESULT,HWND,UINT,WPARAM,LPARAM>   DefMDIChildProc;
  304.     TModuleProc4<int,HWND,LPCSTR,LPCSTR,UINT>       MessageBox;
  305.     TModuleProc0<HBRUSH> GetPattern;
  306.     TModuleProc0<DWORD>  GetVersion;
  307. };
  308.  
  309. //
  310. // class TCtl3dDll
  311. // ~~~~~ ~~~~~~~~~
  312. // Wrapper for the Control 3D Dll
  313. //
  314. class _OWLCLASS TCtl3dDll : public TModule {
  315.   public:
  316.     TCtl3dDll();
  317.  
  318.     // Used by TApplication
  319.     //
  320.     TModuleProc1<BOOL,HANDLE> Register;
  321.     TModuleProc1<BOOL,HANDLE> Unregister;
  322.     TModuleProc1<BOOL,HANDLE> AutoSubclass;
  323.  
  324.     // Used by TDialog
  325.     //
  326.     TModuleProc3<HBRUSH,uint,WPARAM,LPARAM> CtlColorEx;
  327.     TModuleProc2<BOOL,HWND,uint16>          SubclassDlg;
  328.  
  329.     // Not used by OWL
  330.     //
  331.     TModuleProc2<BOOL,HWND,DWORD> SubclassDlgEx;
  332.     TModuleProc0<WORD> GetVer;
  333.     TModuleProc0<BOOL> Enabled;
  334.     TModuleProc0<BOOL> ColorChange;
  335.     TModuleProc1<BOOL,HWND> SubclassCtl;
  336.     TModuleProc4<LONG,HWND,UINT,WPARAM,LPARAM> DlgFramePaint;
  337.  
  338.     TModuleProc0<int> WinIniChange;
  339. };
  340.  
  341. //
  342. // class TXInvalidMainWindow
  343. // ~~~~~ ~~~~~~~~~~~~~~~~~~~
  344. class _OWLCLASS_RTL TXInvalidMainWindow : public TXOwl {
  345.   public:
  346.     TXInvalidMainWindow();
  347.  
  348. #if defined(BI_NO_COVAR_RET)
  349.     TXBase* Clone();
  350. #else
  351.     TXInvalidMainWindow* Clone();
  352. #endif
  353.     void Throw();
  354.  
  355.     static void Raise();
  356. };
  357.  
  358. // Generic definitions/compiler options (eg. alignment) following the
  359. // definition of classes
  360. #include <services/posclass.h>
  361.  
  362. #if defined(BI_NAMESPACE)
  363. } // namespace OWL
  364. #endif
  365.  
  366. //----------------------------------------------------------------------------
  367. // Inline implementations
  368.  
  369. //
  370. // Return the current main window.
  371. //
  372. inline TFrameWindow* TApplication::GetMainWindow()
  373. {
  374.   return MainWindow;
  375. }
  376.  
  377. //
  378. // Return the current document manager.
  379. //
  380. inline TDocManager* TApplication::GetDocManager()
  381. {
  382.   return DocManager;
  383. }
  384.  
  385. //
  386. // Return the HINSTANCE of the previous running instance.
  387. //
  388. inline HINSTANCE TApplication::GetPrevInstance() const
  389. {
  390.   return hPrevInstance;
  391. }
  392.  
  393. //
  394. // Set the previous instance.
  395. // This should not be called by normal programs.
  396. //
  397. inline void TApplication::SetPrevInstance(HINSTANCE pi)
  398. {
  399.   hPrevInstance = pi;
  400. }
  401.  
  402. //
  403. // Retrieve the initial state of the main window.
  404. //
  405. inline int TApplication::GetCmdShow() const
  406. {
  407.   return nCmdShow;
  408. }
  409.  
  410. //
  411. // Sets the initial state of the main window.
  412. // Typically passed by the operating system.
  413. //
  414. inline void TApplication::SetCmdShow(int cmdshow)
  415. {
  416.   nCmdShow = cmdshow;
  417. }
  418.  
  419. //
  420. // Return the command line of the application.
  421. // Most programs do not need to call this because OwlMain has the
  422. // parameters already parsed.
  423. //
  424. inline string& TApplication::GetCmdLine()
  425. {
  426.   return GetInitCmdLine();
  427. }
  428.  
  429. //
  430. // Return the current event from the message queue.
  431. //
  432. inline TCurrentEvent& TApplication::GetCurrentEvent()
  433. {
  434.   return CurrentEvent;
  435. }
  436.  
  437. #if defined(BI_PLAT_WIN16) || defined(WIN32S_SUPPORT)
  438. //
  439. // Return the exception handling state.
  440. //
  441. inline int TApplication::QueryThrow() const
  442. {
  443.   return XState;
  444. }
  445. #endif
  446.  
  447. #if defined(BI_NAMESPACE)
  448. namespace OWL {
  449. #endif
  450.  
  451. extern TWindow* GetWindowPtr(HWND, const TApplication*);
  452.  
  453. #if defined(BI_NAMESPACE)
  454. } // namespace OWL
  455. #endif
  456.  
  457. //
  458. // Return the window pointer given a window's handle.
  459. //
  460. inline TWindow* TApplication::GetWindowPtr(HWND hWnd) const
  461. {
  462. #if defined(BI_NAMESPACE)
  463.   return OWL::GetWindowPtr(hWnd, this);
  464. #else
  465.   return ::GetWindowPtr(hWnd, this);
  466. #endif
  467. }
  468.  
  469. //
  470. // Set the data members with data from WinMain.
  471. //
  472. inline void TApplication::SetWinMainParams(HINSTANCE       hInstance,
  473.                                            HINSTANCE       hPrevInstance,
  474.                                            const char far* cmdLine,
  475.                                            int             cmdShow)
  476. {
  477.   InitHInstance = hInstance;
  478.   InitHPrevInstance = hPrevInstance;
  479.   GetInitCmdLine() = cmdLine;
  480.   InitCmdShow = cmdShow;
  481. }
  482.  
  483. //
  484. // Retrieve the WinMain parameters.
  485. //
  486. inline void TApplication::GetWinMainParams()
  487. {
  488.   InitModule(InitHInstance, GetInitCmdLine().c_str());
  489.   hPrevInstance = InitHPrevInstance;
  490.   nCmdShow = InitCmdShow;
  491. }
  492.  
  493. //
  494. // Returns true if the BWCC is enabled for the application.
  495. //
  496. inline bool TApplication::BWCCEnabled() const
  497. {
  498.   return BWCCOn;
  499. }
  500.  
  501. //
  502. // If BWCC is enabled, return the module associated with it.
  503. //
  504. inline TBwccDll* TApplication::GetBWCCModule() const
  505. {
  506.   return BWCCModule;
  507. }
  508.  
  509. //
  510. // Returns true if Ctl3d is enabled.
  511. //
  512. inline bool TApplication::Ctl3dEnabled() const
  513. {
  514.   return Ctl3dOn;
  515. }
  516.  
  517. //
  518. // If Ctl3D is enabled, return the module associated with it.
  519. //
  520. inline TCtl3dDll* TApplication::GetCtl3dModule() const
  521. {
  522.   return Ctl3dModule;
  523. }
  524.  
  525. #endif  // OWL_APPLICAT_H
  526.